<template>
  <div class="details-container" @touchmove.prevent>
      <div class="top-bar" ><span class="goback" ref='goback' @click='goBack'></span>商品详情</div>
        <Swiper1 ref='swiper1'></Swiper1>
        <!-- 滑动层 -->
        <div class="scroll-wrapper">
            <div class="scroll-content">
                <!-- 名称价格 -->
                <div class="title flex-r-b">
                    <div class="left">
                        <p class="name ellipsis">法式布蕾蛋糕 Pandora</h3>
                        <p>副本描述/商品规格</p>
                    </div>
                    <span class="price">￥178</span>
                    
                </div>
                <!-- 基本参数 -->
                <h3>参数详情</h3>
                <div class="icon flex-r-b">
                    <div class="left"></div>
                    <div class="right flex-c-b">
                        <p>1件商品</p>
                        <p>含五件餐具</p>
                        <p>适合4-6人分享</p>
                    </div>
                </div>
                <!-- 规格 -->
                <h3>规格选择</h3>
                <div class="size-box">
                    <div class="flex-r-b">
                        <label class="radio-label" for='size1'>
                            <input type="radio" name='size' id='size1' checked/>
                            <span class="size-checked">6寸 15cmX15cm</span>
                        </label>
                        <label class="radio-label" for='size2'>
                            <input type="radio" name='size' id='size2'/>
                            <span class="size-checked">6寸 15cmX15cm</span>
                        </label>
                        <label class="radio-label" for='size3'>
                            <input type="radio" name='size' id='size3'/>
                            <span class="size-checked">6寸 15cmX15cm</span>
                        </label>
                    </div>
                </div>
                <!-- 介绍与评价 tab分页-->
                <div class="description-wrapper ">
                    <div class="swiper-container swiper2" ref='swiper2'>
                        <div class="swiper-wrapper">
                            <!-- //商品介绍 tab -->
                            <div class="swiper-slide tab1">
                                <div class="title">产品介绍</div>
                                <div class="content">
                                    <p>浓郁香醇的巧克力，点缀颗颗坚果</p>
                                    <p>浓郁香醇的巧克力，点缀颗颗坚果</p>
                                    <p>口味： 巧克力味</p>
                                    <p>甜度：<span>&nbsp★&nbsp</span><span>&nbsp★&nbsp</span><span>&nbsp★&nbsp</span><span>&nbsp☆&nbsp</span><span>&nbsp☆&nbsp</span></p>
                                    <p>原材料：<span>巧克力、</span><span>巧克力、</span><span>巧克力、</span><span>巧克力、</span><span>巧克力、</span><span>巧克力、</span><span>巧克力、</span></p>
                                    <div class="img">
                                        <img src="../../public/images/index/img_8.png" alt="">
                                    </div>
                                </div>
                            </div>
                            <!-- 商品评价 tab -->
                            <div class="swiper-slide tab2">
                                <img src="../../public/images/index/img_5.png" alt="">
                                <div class="tab-content">
                                    <p>1231</p>
                                    <p>1231</p>
                                    <p>1231</p>
                                    <p>1231</p>
                                    <p>1231</p>
                                    <p>1231</p>
                                </div>
                            </div>
                        </div>
                        <!-- 如果需要分页器 -->
                        <div class="swiper-pagination" ref='pagination'></div>
                    </div>
                </div>

            </div>
        </div>

        <!-- 添加到购物车 -->
        <div class="bottom-bar flex-r-b">
            <div class="cart"><span class="count">88888</span></div>
            <div class="btn addToCart">加入购物车</div>
            <div class="btn">立即购买</div>
        </div>
  </div>
</template>

<script>
import Swiper1 from "@/components/Swiper";
import BScroll from "better-scroll";
// import Swiper from 'swiper';
export default {
  components: {
    Swiper1
  },
  props: {
    scrollY: 0
  },
  data() {
    return {};
  },
  created() {},
  mounted() {
    this.$nextTick(() => {
      this.initScroll();
    });
  },
  computed: {},
  methods: {
    goBack() {
      this.$router.go(-1);
    },
    initScroll() {
      //滚动
      if (this.scroll) return;
      this.scroll = new BScroll(".scroll-wrapper", {
        probeType: 3,
        click: true
      });
      // 描述与评价 tab分页 swiper2
      var txt = ["商品详情", "商品评价"];
      var el = this.$refs.swiper2;
      this.swiper2 = new Swiper(el, {
        iOSEdgeSwipeDetection: true,
        iOSEdgeSwipeThreshold: 50,
        spaceBetween: 5,
        autoHeight: true,
        pagination: {
          el: this.$refs.pagination,
          clickable: true,
          renderBullet: function(index, className) {
            return '<span class="' + className + '">' + txt[index] + "</span>";
          }
        }
      });

      this.swiper2.on("slideChange", () => {
        //手动刷新 滚动层
        // this.scroll.refresh()
        console.log(this.activeIndex);
      });

      this.scroll.on("scroll", function({ y }) {
        this.scrollY = y;
        console.log(this.scrollY);
      });
      this.swiper1 = this.$refs.swiper1;
      console.log(this.swiper1)
    }
  },
  watch: {
    scrollY(y) {
      // swiper1 滑动与放大效果

      if (y >= 0) {
        var precent = 1 + 0.5 * y / swiper1.offsetHeight;
        this.$refs.swiper1.style.transformOrigin = "center top";
        this.$refs.swiper1.style.transform = `scale(${precent})`;
      } else {
        this.$refs.swiper1.style.transform = `translate3d(0,${y * 0.3}px,0)`;
      }
    }
  }
};
</script>
<style lang="scss" scoped>
@import "../../public/sass/base.scss";

$rem-24: 0.24rem;
.details-container {
  height: 100%;
  overflow: hidden;
  padding: 1rem $rem-24 1.5rem $rem-24;
  .top-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    font-family: $f-Regular;
    font-size: 0.32rem;
    color: $c-2a;
    letter-spacing: 0.05rem;
    text-align: center;
    padding: 0.2rem 0.24rem;
    z-index: 9;
    background: white;
    .goback {
      position: absolute;
      left: 0;
      top: 0;
      height: 100%;
      width: 1rem;
      background: url("../../public/images/icon/icon_16.png") no-repeat;
      background-size: 0.16rem 0.32rem;
      background-position: 0.24rem center;
    }
  }

  .swiper1 {
    z-index: 0;
  }
  //滑动层
  .scroll-wrapper {
    position: absolute;
    top: 4.6rem;
    bottom: 0;
    right: 0;
    left: 0;
    padding: 0 0.24rem;
    overflow: visible;
    .scroll-content {
      padding-bottom: 1rem;
      background: white;
      > .title {
        padding: 0.15rem 0;
        @include bottom-border-1px($c-ef);
        p {
          line-height: 0.6rem;
          color: $c-99;
          font-size: 0.24rem;
          font-family: $f-Regular;
          &.name {
            font-size: 0.3rem;
            font-family: $f-Medium;
            color: $c-33;
          }
        }
        .price {
          font-size: 0.34rem;
          color: $c-33;
          font-family: $f-Medium;
        }
      }
      // 基本参数
      h3 {
        font-size: 0.28rem;
        font-family: $f-Bold;
        color: $c-33;
        margin: 0.3rem 0;
      }
      .icon {
        @include bottom-border-1px($c-ef);
        padding-bottom: 0.3rem;
        .left {
          height: 1.7rem;
          width: 3.31rem;
          border-radius: $radius-10;
          background: url("../../public/images/index/img_7.png");
          background-size: 100%;
        }
        .right {
          height: 1.7rem;
          width: 3.31rem;
          font-family: $f-Regular;
          font-size: 0.24rem;
          color: $c-33;
          padding: 0.1rem 0;
          p {
            padding: 0 0.52rem;
            background-position: left center;
            background-repeat: no-repeat;
            &:nth-child(1) {
              background-image: url("../../public/images/icon/icon_11.png");
              background-size: 0.28rem 0.28rem;
            }
            &:nth-child(2) {
              background-image: url("../../public/images/icon/icon_13.png");
              background-size: 0.22rem 0.3rem;
            }
            &:nth-child(3) {
              background-image: url("../../public/images/icon/icon_12.png");
              background-size: 0.26rem 0.29rem;
            }
          }
        }
      }

      //规格
      .size-box {
        padding-bottom: 0.1rem;
        @include bottom-border-1px($c-ef);
        .flex-r-b {
          flex-wrap: wrap;
        }
        .radio-label {
          display: block;
          text-align: center;
          color: $c-33;
          font-size: 0.26rem;
          font-family: $f-Regular;
          margin-bottom: 0.3rem;
          input[type="radio"] {
            position: absolute;
            left: -9999rem;
          }
          .size-checked {
            display: block;
            height: 0.65rem;
            width: 3.35rem;
            background: $c-fa;
            border-radius: 0.32rem;
            line-height: 0.65rem;
          }
          input[type="radio"]:checked + span {
            color: white;
            background: $c-ffba17;
            animation: scaleSize 0.5s;
          }
        }
      }
      //介绍与评价
      .description-wrapper {
        overflow: hidden;
        padding-top: 1.5rem;
        font-family: $f-Regular;
        .swiper2 {
          overflow: visible;
          height: auto;
        }
        .swiper-pagination {
          bottom: 100%;
          padding: 0.3rem 0;
          .swiper-pagination-bullet {
            width: 3.5rem;
            height: 0.76rem;
            margin: 0;
            line-height: 0.76rem;
            font-size: 0.28rem;
            background: $c-fb;
            color: $c-33;
            &:nth-child(1) {
              border-radius: 0.37rem 0 0 0.37rem;
            }
            &:nth-child(2) {
              border-radius: 0 0.37rem 0.37rem 0;
            }
          }
          .swiper-pagination-bullet-active {
            background: $c-ffba17;
            color: white;
          }
        }
        // 介绍页
        .tab1 {
          .title {
            color: $c-33;
            font-size: 0.28rem;
            padding-bottom: 0.3rem;
          }
          .content {
            p {
              color: $c-99;
              font-size: 0.26rem;
              margin-bottom: 0.2rem;
              span {
                display: inline-block;
              }
            }
            .img {
              width: 100%;
              height: 4.83rem;
            }
          }
        }
      }
    }
  }
  //添加到购物车
  .bottom-bar {
    left: 0;
    position: absolute;
    width: 100%;
    height: 0.98rem;
    bottom: 0;
    text-align: center;
    font-size: 0.3rem;
    letter-spacing: 0.03rem;
    z-index: 0;
    background: white;
    .cart {
      flex: 1;
      height: 100%;
      position: relative;
      background: url("../../public/images/icon/icon_15.png") no-repeat;
      background-size: 0.56rem 0.48rem;
      background-position: 0.26rem 0.35rem;
      .count {
        position: absolute;
        top: 0.1rem;
        left: 0.55rem;
        padding: 0 0.09rem 0 0.13rem;
        line-height: 0.44rem;
        text-align: center;
        height: 0.44rem;
        min-width: 0.44rem;
        border-radius: 0.22rem;
        background: $c-ffba17;
        color: white;
        font-size: 0.24rem;
      }
    }
    .btn {
      color: $c-ffba17;
      background: $c-fb;
      width: 2.88rem;
      height: 100%;
      line-height: 0.98rem;
      &:nth-child(3) {
        color: white;
        background: $c-ffba17;
      }
    }
  }
  // 添加购物车
  .bottom-bar {
    position: fixed;
    z-index: 9;
    .scaleCount {
      animation: scaleCount 0.5s;
    }
  }

  @keyframes scaleCount {
    50% {
      transform: scale3d(1.5, 1.5, 1);
    }
  }
  @keyframes scaleSize {
    50% {
      transform: scale3d(1.05, 1.05, 1);
    }
  }
}
</style>